/**
 * 全屏宽度功能（安全版）
 * 去除对 frappe.ready 的依赖，避免在 Desk 下报错；仅做最小样式修正
 */
(function () {
    function applyFullWidth() {
        try {
            var pageBody = document.querySelector('.page-body');
            if (pageBody) pageBody.classList.add('full-width');

            var containers = document.querySelectorAll('.container');
            containers.forEach(function (container) {
                container.style.maxWidth = '100%';
                container.style.width = '100%';
            });

            var workspaceContent = document.querySelector('.workspace-content');
            if (workspaceContent) {
                workspaceContent.style.maxWidth = '100%';
                workspaceContent.style.width = '100%';
            }

            var cards = document.querySelectorAll('.card');
            cards.forEach(function (card) {
                card.style.marginLeft = '0';
                card.style.marginRight = '0';
            });
        } catch (e) {
            // no-op
        }
    }

    function ready(fn) {
        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', fn);
        } else {
            fn();
        }
    }

    ready(function () {
        setTimeout(applyFullWidth, 300);
    });

    try {
        if (window.frappe && frappe.router && typeof frappe.router.on === 'function') {
            frappe.router.on('change', function () { setTimeout(applyFullWidth, 200); });
        }
    } catch (e) {}
})();
